var MemberNavCtrl = ['$scope', '$rootScope', '$routeParams', 'VIP', '$location', function ($scope, $rootScope, $routeParams, VIP, $location) {
        $scope.menu_list = [
            {name: $rootScope.language.TIPS_MONTH_BIRTHDAY_VIP, url: "#member/list/birthday_member", id: "birthday_member", show: $rootScope.purview['\/MemberNavCtrl\/birthday_member'].show},
            {name: $rootScope.language.TIPS_RECENT_VIP, url: "#member/list/recent_member", id: "recent_member", show: $rootScope.purview['\/MemberNavCtrl\/recent_member'].show},
            {name: $rootScope.language.TIPS_DETECTION_VIP, url: "#member/list/induced_member", id: "induced_member", show: $rootScope.purview['\/MemberNavCtrl\/induced_member'].show},
            {name: $rootScope.language.TIPS_POINT_VIP, url: "#member/list/point_member", id: "point_member", show: $rootScope.purview['\/MemberNavCtrl\/point_member'].show}
        ];
        //会员搜索
        $scope.memberSearch = function (ret) {
            //权限检查
            if ($rootScope.purviewCheckChange('\/MemberNavCtrl\/memberSearch')) {
                return;
            }
            if (typeof ret == "undefined") {
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_MEMBER_TEL_CHECK});
            } else {
                VIP.vip_search({'tel': ret}).then(function (response) {
                    if (response.data.status == 1) {
                        $location.path('/member/member_detail/' + ret);
                    } else {
                        baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_MEMBER_USER_CHECK});
                    }
                }).catch(function (err) {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
      
                });
            }
        };
        //店内会员、 周边客流量
        $scope.member_num = $rootScope.member_num;
    }];

//店内感应到的会员(还没做)
var MemberInducedMemberCtrl = ['$scope', 'UserLoginCheck', 'ShopSetCheck', function ($scope, UserLoginCheck, ShopSetCheck) {
        UserLoginCheck();
        ShopSetCheck();
        $scope.curr = 'induced_member';
        $scope.member_list = [];
    }];

//当月生日会员
var MemberBirthdayMemberCtrl = ['$scope', 'VIP', 'UserLoginCheck', 'ShopSetCheck', 'timeStamp2String', '$rootScope', function ($scope, VIP, UserLoginCheck, ShopSetCheck, timeStamp2String, $rootScope) {
        UserLoginCheck();
        ShopSetCheck();
        $rootScope.curr = 'birthday_member';
        $scope.cur_pagenum = 1;
        $scope.buttonMore = 1;
        // if($rootScope.reback != undefined && $rootScope.reback == 1){
        //     $rootScope.reback = 0;
        //     $scope.cur_pagenum = $rootScope.cur_pagenum;
        // }
        
        // else{
        //     $rootScope.member_list = [];
        // }
        $scope.huiyuan = "";
        $scope.scoll = {};

        $scope.member_list = [];
        var _configData = $api.getStorage('configData');
        //获取当前页会员信息
        var get_cur_page_vip_list = function(){

             //会员查询条件
            var nowTime = new Date();
            var nowMonth = timeStamp2String(nowTime, 'month');
            var param = {};
            param.fields = '*';
            param.month = nowMonth;
            param.source = '6';
            param.shop_code = $rootScope.current_shop.ShopCode;
            param.pageNum = $scope.cur_pagenum;
            //$rootScope.cur_pagenum = $scope.cur_pagenum;
            param.num = _configData.vip_list_num;
            baison_app.api.showProgress({
                text: '',
                title: $rootScope.language.TIPS_DATA_NOT_DOWN,
                modal: false
            });
            VIP.get_list_month(param).then(function (ret) {
                console.log(ret);
                baison_app.api.hideProgress();
                if (ret.data.data != undefined && ret.data.data.vip != undefined && ret.data.data.vip.data != undefined && ret.data.data.vip.data.length > 0) {
                    if(ret.data.data.vip.count < $scope.cur_pagenum*_configData.vip_list_num){
                        $scope.buttonMore = 0; 
                    }else{
						$scope.buttonMore = 1;
					}
                    $.each(ret.data.data.vip.data,function(i,n){
                        $scope.member_list.push(n);
                    }); 
                    
                    //有图片的话返回图片，没图片的话取本地默认的
                    $.each(ret.data.data.vip.data, function (i, n) {
                        if (n.customer_headphoto == '') {
                            n.customer_headphoto = './image/vip_head_img01.jpg';
                        }
                        var nowTime = new Date();
                        var nowMonth = timeStamp2String(nowTime, 'date');
                        //生日格式为1999-09-09  或者   09-09   用slice取倒数第5和4位为月份
                        if (n.birthday && n.birthday.slice(-5) == nowMonth.slice(-5)) {
                            n.birthdayToday = 1;
                        } else {
                            n.birthdayToday = 0;
                        }
                    });
                    
                    
                } else {
                    $scope.buttonMore = 0; 
                    $scope.member_list = [];
                }

            }).catch(function (err) {
                $scope.member_list = [];
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                baison_app.api.hideProgress();
                
            });


            
        };

        //更多
        $scope.scoll.nextpage = function(){
            $scope.cur_pagenum++;
            get_cur_page_vip_list();
            
        };
        //获取当前页会员信息
        get_cur_page_vip_list();
       
    }];

//最近消费会员
var MemberRecentMemberCtrl = ['$rootScope', '$scope', 'VIP', 'UserLoginCheck', 'ShopSetCheck', 'changeDate', 'timeStamp2String', function ($rootScope,$scope, VIP, UserLoginCheck, ShopSetCheck, changeDate, timeStamp2String) {
        
        UserLoginCheck();
        ShopSetCheck();
        $rootScope.curr = 'recent_member';
        $scope.cur_pagenum = 1;
        $scope.buttonMore = 1;
        // if($rootScope.reback != undefined && $rootScope.reback == 1){
        //     $rootScope.reback = 0;
        //     $scope.cur_pagenum = $rootScope.cur_pagenum;
        // }
        
        // else{
        //     $rootScope.member_list = [];
        // }
        $scope.member_list = [];
        $scope.scoll = {};
        var _configData = $api.getStorage('configData');
        //获取当前页会员信息
        var get_cur_page_vip_list = function(){
            var lastTime = changeDate(7, '1');
            var param = {
                'shop_code': $rootScope.current_shop.ShopCode,
                'pageNum':$scope.cur_pagenum,
                'num': _configData.vip_list_num,
                'date':lastTime
            };
            //$rootScope.cur_pagenum = $scope.cur_pagenum;

            VIP.get_list_recent(param).then(function (ret) {
                baison_app.api.hideProgress();
                //图片
                if (ret.data.data != undefined && ret.data.data.data.length > 0) {
                    if(!ret.data.data.count){
                        $scope.buttonMore = 0;
                    }else if(ret.data.data.count < $scope.cur_pagenum*_configData.vip_list_num){
						$scope.buttonMore = 0;
					}else{
						$scope.buttonMore = 1;
					}
                    var data = ret.data.data.data;
                    //获取当前页会员信息
                    $.each(data,function(i,n){
                        $scope.member_list.push(n);
                    }); 
                    
                    $.each($scope.member_list, function (i, n) {
                        if (n.customer_headphoto == '') {
                            n.customer_headphoto = './image/vip_head_img01.jpg';
                        }
                        var nowTime = new Date();
                        var nowMonth = timeStamp2String(nowTime, 'date');
                        //生日格式为1999-09-09  或者   09-09   用slice取倒数第5和4位为月份
                        if (n.birthday && n.birthday.slice(-5) == nowMonth.slice(-5)) {
                            n.birthdayToday = 1;
                        } else {
                            n.birthdayToday = 0;
                        }
                    });
                    
                } else {
                    $scope.buttonMore = 0;
                    $scope.member_list = [];
                }

    //            }
            }).catch(function (err) {
                $scope.member_list = [];
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                baison_app.api.hideProgress();
            });
            
        };

        //更多
        $scope.scoll.nextpage = function(){
            $scope.cur_pagenum++;
            get_cur_page_vip_list();
        };
        get_cur_page_vip_list();
        baison_app.api.showProgress({
            text: '',
            title: $rootScope.language.TIPS_DATA_NOT_DOWN,
            modal: false
        });
        

        
    }];
//会员积分到期提醒
var MemberPointMaturityCtrl = ['$rootScope', '$scope', 'VIP', 'UserLoginCheck', 'ShopSetCheck', 'changeDate', 'timeStamp2String', function ($rootScope, $scope, VIP, UserLoginCheck, ShopSetCheck, changeDate, timeStamp2String) {
        UserLoginCheck();
        ShopSetCheck();
        $scope.curr = 'point_member';
        $scope.pageNum = '1';
        $scope.tab_index = '3';
        $scope.changePointType = function (pointType) {
            $scope.pointType = pointType;
            VIP.get_list_point_maturity($scope.pointType, 1).then(function (ret) {
                //图片
                if (ret.data.data != undefined) {
                    $scope.member_list = ret.data.data.data;
                    $.each($scope.member_list, function (i, n) {
                        if (n.customer_headphoto == '') {
                            n.customer_headphoto = './image/vip_head_img01.jpg';
                        }
                        var nowTime = new Date();
                        var nowMonth = timeStamp2String(nowTime, 'date');
                        //生日格式为1999-09-09  或者   09-09   用slice取倒数第5和4位为月份
                        if (n.birthday && n.birthday.slice(-5) == nowMonth.slice(-5)) {
                            n.birthdayToday = 1;
                        } else {
                            n.birthdayToday = 0;
                        }
                    });
                } else {
                    $scope.member_list = [];
                }
            }).catch(function (err) {
                $scope.member_list = [];
            });
            $scope.tab_index = pointType;
        };
        $scope.changePointType('3');
        $scope.nextPage = function () {
            $scope.pageNum = $scope.pageNum * 1 + 1;
            VIP.get_list_point_maturity($scope.pointType, $scope.pageNum).then(function (ret) {
                if (ret.data.data != undefined || ret.data.data.data.length == '0') {
                    baison_app.api.toast({msg: $rootScope.language.TIPS_CUNHUO_MESSAGE});
                    return;
                }
                ret.data.data.data.forEach(function (n) {
                    $scope.member_list.push(n);
                });
//                $scope.member_list.push(ret.data.data.data);
            });
        };
    }];

//会员详情页面
var MemberDetailCtrl = ['$q', '$scope', '$routeParams', 'VIP', 'timeStamp2String', '$rootScope', 'BaseDaoGou','ThirdDev','dbSelect', function ($q,$scope, $routeParams, VIP, timeStamp2String, $rootScope, BaseDaoGou,ThirdDev,dbSelect) {
//详情的TAB页
        $scope.scoll = {};
        var configData = $api.getStorage('configData');
        $scope.is_lqx = ThirdDev.is_lqx();
        $scope.curr = 'recent_goods';
        $scope.buttonMore = 1;
//获取会员信息
        $scope.vip_info = [];
        VIP.vip_search({'tel': $routeParams.vip_code, 'record_detail': 1}).then(function (response) {
            $scope.vip_info = response.data.data;
            //获取会员头像
            if ($scope.vip_info.customer_headphoto == '') {
                $scope.vip_info.customer_headphoto = './image/vip_head_img01.jpg';
            }
            $scope.vip_info.is_add_time = timeStamp2String(response.data.data.is_add_time, 'date');
        });
        
        //获取相应名称
        var get_recent_comsute_name = function(res){
            var deferred = {};
            var promise = {};
            res.forEach(function(n,i){
                deferred[i] = $q.defer();
                promise[i] = deferred[i].promise;
                var sku_name_sql = 'select GoodsName from PosSku where SkuCode ="'+n.sku+'"';
                dbSelect('YsPos', sku_name_sql).then(function(skuname){
                    n.goods_name = skuname[0]?skuname[0].GoodsName:'';
                    var shop_name_sql = 'select ShopName from PosShop where ShopCode ="'+n.shop_code+'"';
                    dbSelect('YsPos', shop_name_sql).then(function(shopname){
                        n.shop_name = shopname[0]?shopname[0].ShopName:'';
                        deferred[i].resolve('success');
                    });
                });
                
            });
            return $q.all(promise);
        };
        //获取购买记录
        var get_huiyuan_history_list = function(){
            var param = {
                'pageNum':$scope.cur_pagenum,
                'num':configData.buy_list_num,
                'tel':$routeParams.vip_code
            };

            VIP.get_huiyuan_history(param).then(function (response) {
                if (response.data.status == 1) {
                    if (response.data.data.data.length != 0) {
                        if(!response.data.data.count){
                            $scope.buttonMore = 0;
                        }else if(response.data.data.count < $scope.cur_pagenum*configData.buy_list_num){
							$scope.buttonMore = 0;
						}else{
							$scope.buttonMore = 1;
						}
                        get_recent_comsute_name(response.data.data.data).then(function(){
                            $.each(response.data.data.data,function(i,n){
                                $scope.menu_detail_recent_list.push(n);
                            });
                            //$scope.menu_detail_recent_list = response.data.data;
                        });
                        
                    }else{
                        $scope.buttonMore = 0;
                    }
                }else{
                    $scope.buttonMore = 0;
                }
            });

        };

        //更多
        $scope.scoll.nextpage = function(){
            
            $scope.cur_pagenum++;
            get_huiyuan_history_list();
            
        };
        
        //获取会员最近消费记录
        $scope.recent = function () {
            $scope.curr = 'curr_recent';
            $scope.menu_detail_recent_list = [];
            $scope.cur_pagenum = 1;
            

            get_huiyuan_history_list();

        };
        //获取推荐商品信息
        $scope.recommend = function () {
            $scope.curr = 'curr_recommend';
            //0：林清轩使用
            $scope.menu_detail_recommend_list = [
                {goods_name: '面膜棒', goods_size: '', buy_price: '15.00', goods_disc: '0.8', sku: '1111111100003'},
                {goods_name: '小园镜', goods_size: '', buy_price: '25.00', goods_disc: '0.5', sku: '1111111100005'},
                {goods_name: '天然麻洗脸扑', goods_size: '', buy_price: '15.00', goods_disc: '0.6', sku: '1111111100002'},
                {goods_name: '化妆包', goods_size: '', buy_price: '38.00', goods_disc: '0.6', sku: '1111111100010'},
                {goods_name: '檀香梳', goods_size: '', buy_price: '40.00', goods_disc: '0.9', sku: '1111111100004'},
                {goods_name: '木质钥匙扣', goods_size: '', buy_price: '9.00', goods_disc: '0.7', sku: '1111111100009'},
                {goods_name: '木质皂架', goods_size: '', buy_price: '30.00', goods_disc: '0.7', sku: '1111111100006'}
            ];
            
            $(function () {

                //推荐商品滑动
                var mySwiperGoods = new Swiper('.swiper-container-goods', {
                    paginationHide: true,
                    slidesPerView: 4,
                    freeMode: true,
                    keyboardControl: true,
                    mousewheelControl: true,
                    observer: true, //修改swiper自己或子元素时，自动初始化swiper
                    observeParents: true, //修改swiper的父元素时，自动初始化swiper
                });
            });
        };
        //获取会员卡积分变动
        $scope.memberCard = function () {
            $scope.curr = 'curr_card';
            $scope.pageNum = 1;
            VIP.get_huiyuan_change($routeParams.vip_code,$scope.pageNum).then(function (ret) {
                
                $scope.memberRecordDetail = ret.data;
            });
        };

        $scope.memberCardMore = function () {
            $scope.pageNum++;
            $scope.memberRecordDetail = $scope.memberRecordDetail || [];
            VIP.get_huiyuan_change($routeParams.vip_code,$scope.pageNum).then(function (ret) {
                ret.data.forEach(function (d,i) {
                    $scope.memberRecordDetail.push(d);
                });
            });
        };
        //获取会员相关的优惠券
        $scope.memberCoupon = function () {
            $scope.curr = 'curr_coupon';
            VIP.get_huiyuan_coupon($routeParams.vip_code).then(function (ret) {
                ret.data.data.forEach(function (n) {
                    if (n.is_use == 0){
                         n.coupon_code = n.coupon_code.substr(0,3)+'***';
                    }
                });
                $scope.memberCouponDetail = ret.data.data;
            });
        };
        $scope.recent();
    }];

var MemberAddCtrl = ['$scope', 'VIP', 'PosUser', '$rootScope', '$location', 'dbUpdate', 'ngDialog', 'GoodsCart', function ($scope, VIP, PosUser, $rootScope, $location, dbUpdate, ngDialog, GoodsCart) {

        $rootScope.purviewCheckChange('\/MemberAddCtrl', '/member/list/birthday_member');
        $scope.memberData = {};
        $scope.memberData.email = '';
        $scope.hasEmail = false;
        //cancelled by lqx maowei on 20170310 注释掉原来的new Date()
        //$scope.memberData.birthday = new Date();
        //added by lqx maowei on 20170310 把memberData.birthday转换为yy-mm-dd
        $scope.memberData.birthday = "1985/6/15";

        //默认没有实体卡，默认性别为女
        $scope.memberData.card = '2';
        $scope.memberData.sex = '2';
        
        //获取会员可选皮肤类型
        VIP.ger_all_skin_type().then(function (ret) {
            $scope.skinType = ret;
        });
        if ($rootScope.purview['\/MemberAddCtrl\/memberType'].show == 1) {
            //获取会员卡类别
            VIP.get_VIP_category().then(function (ret) {
                $scope.memberData.memberCategory = ret[0].cate_code;
                $scope.VIP_category = ret;
            });
        }
        //获取导购员
        PosUser.get_list_all({'UserStatus': 1, 'ShopCode': $rootScope.current_shop.ShopCode}).then(function (ret) {
            $scope.memberGuide = [];
            if (ret.length > 0) {
                $scope.memberData.UserCode = ret[0].UserCode;
                $scope.memberData.UserName = ret[0].UserName;
            }
            ret.forEach(function (n) {
                $scope.memberGuide.push({
                    UserCode: n.UserCode,
                    UserName: n.UserName
                });
            });

        });
        //城市选择模块
        baison_app.citySelector.close();

        /***added by lqx maowei on 20170313 新增日期选择 JS插件***/
       var currYear = (new Date()).getFullYear();
       $('#appDate').val('').mobiscroll().date({
            theme: 'android-holo',  
            display: 'modal',
            mode: 'scroller',
            lang: 'zh',       
            defaultValue : new Date('1985-06-15'),
            dateFormat: 'yyyy/mm/dd ',
            minWidth: 200,
            startYear:currYear - 90,
            endYear:currYear + 0   
        }).val('1985/06/15');
        
        //手机号
        $scope.newMemberTel = function () {
            $scope.hasEmail = false;
            $scope.curr = 'newMemberTel';
            $scope.add_curr1 = 'curr';
            $scope.add_curr2 = '';
            $scope.add_curr3 = '';
            baison_app.citySelector.close();
        };
        //必填信息
        $scope.newMemberNecessary = function () {
            if (typeof ($scope.memberData.tel) == "undefined") {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_TEL_CHECK});
            } else if ($scope.memberData.tel != $scope.memberData.tel2) {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_TEL_DIFFER});
                $scope.newMemberTel();
            } else if (typeof ($scope.memberData.name) == "undefined") {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_MEMBER_NAME});
                $scope.newMemberTel();
            } else {
                $scope.curr = 'newMemberNecessary';
                $scope.add_curr1 = 'curr';
                $scope.add_curr2 = 'curr';
                $scope.add_curr3 = '';
                
                baison_app.citySelector.close();
            }
        };

        $scope.changeEmail = function(){
            if(typeof $scope.memberData.email == 'string' && $scope.memberData.email.slice($scope.memberData.email.length-1,$scope.memberData.email.length) == '@'){
                //$scope.memberData.email = $scope.memberData.email.substr(0,$scope.memberData.email.length-2);
                $scope.hasEmail = true;
            }
        };

        $scope.toChangeEmail = function(){
            $scope.hasEmail = false;
        };
        
        
        $scope.changeMemberEmail = function(email){
            switch (email){
                case '1':{
                    $scope.memberData.email = $scope.memberData.email+'qq.com';
                    break;
                }
                case '2':{
                    $scope.memberData.email = $scope.memberData.email+'163.com';
                    break;
                }
                case '3':{
                    $scope.memberData.email = $scope.memberData.email+'126.com';
                    break;
                }
                case '4':{
                    $scope.memberData.email = $scope.memberData.email+'gmail.com';
                    break;
                }
                case '5':{
                    $scope.memberData.email = $scope.memberData.email+'hotmail.com';
                    break;
                }
                case '6':{
                    $scope.memberData.email = $scope.memberData.email+'sina.com';
                    break;
                }
                case '7':{
                    $scope.memberData.email = $scope.memberData.email+'sohu.com';
                    break;
                }
            }
            //$scope.memberData.email = $scope.memberData.email+'qq.com';
            
            $scope.hasEmail = false;
        }

        //生日输入验证年龄段
        var change_birthday = function () {
            $scope.configData = $api.getStorage('configData');
            var age = $scope.configData.MemAgeData;

            var thisBirthdayValue = $("#appDate").val();
            /*var birthday = new Date($scope.memberData.birthday);*/
            var birthday = new Date(thisBirthdayValue);
            var datetime = new Date();

            var b_year = birthday.getFullYear();
            var b_month = birthday.getMonth() + 1 < 10 ? "0" + (birthday.getMonth() + 1) : birthday.getMonth() + 1;
            var b_date = birthday.getDate() < 10 ? "0" + birthday.getDate() : birthday.getDate();

            var year = datetime.getFullYear();
            var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
            var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();

            if ((year - b_year) < age.LowerAge || (year - b_year) > age.UpperAge) {
//              $scope.memberData.birthday =0;
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_MEMBER_AGE});
                return 0;
            } else if ((year - b_year) == age.LowerAge || (year - b_year) == age.UpperAge) {
                if (b_month > month) {
//                  $scope.memberData.birthday =0;
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_MEMBER_AGE});
                    return 0;
                } else if (b_month == month) {
                    if (b_date > date) {
//                      $scope.memberData.birthday =0;
                        baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_MEMBER_AGE});
                        return 0;
                    } else {
                        return 1;
                    }
                } else {
                    return 1;
                }

            }
//          return 1;

        };
        //选填信息
        $scope.newMemberOptional = function () {
            if (typeof ($scope.memberData.tel) == "undefined") {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_TEL_CHECK});
                return;
            } else if ($scope.memberData.tel != $scope.memberData.tel2) {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_TEL_DIFFER});
                $scope.newMemberTel();
                return;
            } else if (typeof ($scope.memberData.name) == "undefined") {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_MEMBER_NAME});
                $scope.newMemberTel();
                return;
            }
            if (typeof ($scope.memberData.email) == "undefined") {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_EMAIL_NAME});
                return;
            }
            var reg = "@";
            if(typeof ($scope.memberData.email) == 'string' ){
                //console.log( $scope.memberData.email.indexOf(reg));
                if( $scope.memberData.email.indexOf(reg) == -1){
                    baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_EMAIL_NAME});
                    return;
                }else if( $scope.memberData.email.indexOf(reg) == 0 ||  $scope.memberData.email.indexOf(reg) == $scope.memberData.email.length-1 ){
                    baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_EMAIL_NAME});
                    return;
                }
                
            }
            if (typeof ($scope.memberData.birthday) == "undefined" ||
                    typeof ($scope.memberData.sex) == "undefined" ||
                    typeof ($scope.memberData.UserCode) == "undefined" ||
                    typeof ($scope.memberData.card) == "undefined") {
                baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_NECESS_INFO});
                $scope.newMemberNecessary();
            } else {
                if ($scope.memberData.card == '1') {
                    if (typeof $scope.memberData.cardNo == "undefined") {
                        baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_NECESS_INFO});
                        $scope.newMemberNecessary();
                        return;
                    }
                }
                $scope.hasEmail = false;
                $scope.add_curr1 = 'curr';
                $scope.add_curr2 = 'curr';
                $scope.add_curr3 = 'curr';
                $scope.curr = 'newMemberOptional';
            }
        };
        //打开城市选择器
        $scope.memberCitySet = function () {
            baison_app.citySelector.open({}, function (ret) {
                $("#province").val(ret.province);
                $("#city").val(ret.city);
                $("#district").val(ret.county);
                $scope.memberData.province = ret.province;
                $scope.memberData.city = ret.city;
                $scope.memberData.county = ret.county;
            });
        };
        //关闭城市选择器
        $scope.cityclose = function () {
            baison_app.citySelector.close();
        };
        $scope.newMemberTel();

        $scope.memberAddForm = function (memberData) {
            //added by lqx maowei on 20170313 用JQUERY方法取到日期VAL存入对象memberData中
            var thisBirthdayValue = $("#appDate").val();
            memberData.birthday = thisBirthdayValue;
            if (memberData.card == 2) {
                memberData.cardNo = memberData.tel;
            }
            if (typeof (memberData.birthday) != "undefined") {
                //若年龄的开关打开，则调用年龄设置，否则不调用
                $scope.configData = $api.getStorage('configData');
                if ($scope.configData.membAge == 1) {
                    if (change_birthday() == 0) {
                        return false;
                    }
                }
            }
            
            if ($scope.memberData.rTel != '' && typeof ($scope.memberData.rTel) != 'undefined') {
                var reg = /^(0|86|17951)?((13[0-9])|(15[012356789])|(17[0135678])|(18[0-9])|(14[579]))[0-9]{8}$/;
                if (!reg.test($scope.memberData.rTel)) {
                    baison_app.api.toast({msg: $rootScope.language.TIP_MEMBER_TEL_CHECK});
                    return false;
                }
            }
            var jump = 0;
			VIP.vip_search({vip_code: memberData.tel}).then(function (response) {
                if (response.data.status != 1) {
					VIP.add_huiyuan(memberData).then(function (success) {
						//会员服务器插入成功、本地也插入成功
						if (success != '' && success != undefined) {
							baison_app.api.toast({msg: $rootScope.language.MSG_SAVE_SUCCESS});
							jump = ngDialog.open({closeByDocument: false,
								template: './html/component/confirm.html',
								disableAnimation: true,
								trapFocus: false,
								scope: $scope,
								controller: [function () {
										//标题
										$scope.title = $rootScope.language.TIP_CASHIER_TITLE;
										//内容
										$scope.info = $rootScope.language.MSG_GO_TO_CASHIER;
									}]
							});
							//跳转到收银页面，并把vip信息带入
							$scope.confirm = function () {
								
								VIP.vip_search({vip_code: memberData.tel}).then(function (response) {
									//baison_app.api.alert({msg:response.data.data});
									if (response.data.status == 1) {
										var data = response.data.data;
										if ($rootScope.yxdjsy == "0") {
		//                        baison_app.api.alert({msg: $rootScope.language.TIPS_CASHIER_USE_WILDERCARD});
											return;
										}
										GoodsCart.set_current_vip(data);
										$rootScope.goods_cart.vip.customer_level = data.customer_level;
									} else {
										//$rootScope.goods_cart.vip = {};
										
										baison_app.api.toast({msg: $rootScope.language[response.data.message]}); //弹出服务器返回message
									}
									ngDialog.close(jump);
									$location.path('/cashier/index');
								}).catch(function (err) {
									ngDialog.close(jump);
									$location.path('/cashier/index');
									//网络故障
									baison_app.api.toast({msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET}); //'没有联网'
								});
								
							};
							//取消
							$scope.cancel = function () {
								ngDialog.close(jump);
								$location.path('/member/list/birthday_member');
							};
						}
					}).catch(function (err) {
						baison_app.api.toast({msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
					});
				}else{
					baison_app.api.toast({msg: '该会员已存在'});
				}
			});
            
        };
        //监听路由发生变化，如果页面发生返回，则强制关闭城市选择器
        $scope.$on('$routeChangeStart', function () {
            baison_app.citySelector.close();
        });

    }];
MemberNavCtrl.$injector = ['$scope', '$rootScope', '$routeParams', 'VIP', '$location'];
MemberInducedMemberCtrl.$injector = ['$scope', 'UserLoginCheck', 'ShopSetCheck'];
MemberBirthdayMemberCtrl.$injector = ['$rootScope','$scope', 'VIP', 'UserLoginCheck', 'ShopSetCheck', 'timeStamp2String', '$rootScope'];
MemberRecentMemberCtrl.$injector = ['$rootScope', '$scope', 'VIP', 'UserLoginCheck', 'ShopSetCheck', 'changeDate', 'timeStamp2String'];
MemberPointMaturityCtrl.$injector = ['$rootScope', '$scope', 'VIP', 'UserLoginCheck', 'ShopSetCheck', 'changeDate', 'timeStamp2String'];
MemberDetailCtrl.$injector = ['$q', '$scope', '$routeParams', 'VIP', 'timeStamp2String', '$rootScope', 'BaseDaoGou','ThirdDev','dbSelect'];
MemberAddCtrl.$injector = ['$scope', 'VIP', 'PosUser', '$rootScope', '$location', 'dbUpdate', 'ngDialog', 'GoodsCart'];